import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.UIManager;


public class NodeTrainer {
	
	CustomButton fight = new CustomButton("Kämpa");
	CustomButton run = new CustomButton("Fega ur");
	Player player;
	InterfaceFrame frame;
	

	NodeTrainer(final Player player, final InterfaceFrame frame, final MapNode node){
		
		this.player = player;
		this.frame = frame;
		
		fight.addMouseListener(new TheMouseListener());
		run.addMouseListener(new TheMouseListener());
		
		run.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.nface.textArea.setText("");
				frame.nface.popOptions.removeAll();
				frame.getContentPane().repaint();
			}
		});
		
		fight.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				UIManager.put("MenuItem.selectionBackground", new Color(163,184,204));
				UIManager.put("MenuItem.selectionForeground", Color.BLACK);
				UIManager.put("MenuItem.foreground", Color.BLACK);
				frame.nface.popPrime.setVisible(false);
				frame.swapToCombatSkeleton(node.getTrainer(player), false, node);
			}
			
		});
		
	}
	
	public void show(){
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		String trainerName = frame.nface.node.getTrainer(player).playerName;
		int numberOfPets = frame.nface.node.getTrainer(player).getLivingPets();
		frame.nface.textArea.setText("En tränare som kallar sig " + trainerName + " tittar på dig... \n" +
				"Hen har " + numberOfPets + " husdjur! \n" +
				"Vad vill du göra?");
		if(frame.nface.node.distance == 1)
			frame.nface.textArea.setText("Sista striden.. lycka till! \n" +
					"Mästertränaren här har ett mycket erfaret djur av varje typ, se till att vara redo!");
		frame.nface.popOptions.add(fight);
		frame.nface.popOptions.add(run);
	}
	
	class CustomButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		
		CustomButton(String str){
			super(str);
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(306,50);	
		}
		
	}
	
	private class TheMouseListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e){
		}

		@Override
		public void mouseEntered(MouseEvent e) {
		}

		@Override
		public void mouseExited(MouseEvent e) {
		}
		
		@Override
		public void mousePressed(MouseEvent e) {
			frame.nface.popPrime.show(frame, 50, 55);
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			
		}
		
	}
	
}
